#include "RotationGun.h"
#include "SpriteMaker.h"
RotationGun::RotationGun(b2World *_World) :GunObject(_World)
{
}

RotationGun::~RotationGun()
{
}

void RotationGun::init(SpriteBatchNode* _Spritebatch, SpriteFrameCache* _Cache, Sprite *_Parent)
{
	mId = OBJECT_GUN;
	mIsAction = true;
	mIsCollision = false;

	mBody = new GunBody(mWorld,b2_staticBody);
	mBody->mColBody->SetUserData(this);
	mSprite = SpriteMaker::makeSprite(_Spritebatch, "gun_01.png");
	mSprite->setScaleX(0.5f);
	mAnimation = SpriteMaker::makeAnimation(_Cache, "gun", 1, 4, 1.f);
	mSprite->runAction(mAnimation);
}

void RotationGun::update(float dt)
{
	GunObject::update(dt);
}

void RotationGun::draw()
{
	GunObject::draw();
}

void RotationGun::destroy()
{
	GunObject::destroy();
}

void RotationGun::onCollisionWith(BaseObject *_Object)
{
	switch (_Object->mId)
	{
	case OBJECT_BULLET:
		if (mIsCollision == false)
		{
			mIsAction = true;
			mIsCollision = true;
			makeJointWithBullet(_Object);

			auto actionBy = (RotateTo::create(2, 90));
			this->mSprite->runAction(actionBy);
		}
		break;

	}
}

void RotationGun::initAction()
{
	mAction = RepeatForever::create(RotateBy::create(2, 180));
	mSprite->runAction(mAction);
}
